package com.example.springbootkafka.controller;

import com.example.springbootkafka.producer.KafkaProducer;
import com.example.springbootkafka.constant.MyTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Bruce Lee
 * @Classname TestController
 * @Description
 * @Date 2023-11-22
 */
@RestController
public class TestController {
    @Autowired
    private KafkaProducer kafkaProducer;


    @GetMapping(path = "/test/{msg}")
    public void sendTest(@PathVariable String msg) {
        kafkaProducer.send(MyTopic.TEST,"test.*",msg);
    }

    @GetMapping(path = "/topic1/{msg}")
    public void sendTopic1(@PathVariable String msg) {
        kafkaProducer.send(MyTopic.TOPIC1,3,"topic.*",msg);
    }


    @GetMapping(path = "/topic2/{msg}")
    public void sendTopic2(@PathVariable String msg) {
        kafkaProducer.send(MyTopic.TOPIC2, 1, "topic.*", msg);
    }

}
